//
//  commNavigationBar.m
//  PhotoCircle
//
//  Created by wujungao on 12/19/15.
//  Copyright © 2015 wujungao. All rights reserved.
//

#import "commNavigationBar.h"

@interface commNavigationBar()

@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *backBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;

@end

@implementation commNavigationBar

-(void)awakeFromNib{
    
    [self backBtnAction];
    [self rightBtnAction];
    [self configButton];
}

#pragma mark - config view
-(void)setBackBtnImage:(UIImage *)image forState:(UIControlState)state{
    
    [self.backBtn setImage:image forState:state];
}

-(void)setRightBtnImage:(UIImage *)image forState:(UIControlState)state{
    
    [self.rightBtn setImage:image forState:state];
}

-(void)configTitleWithText:(NSString *)text{
    
    self.titleLabel.text=[NSString stringWithFormat:@"%@",text];
}

-(void)isHiddenButtonWithBtnType:(btnType)buttonType andIsHidden:(BOOL)isHidden{
    
    if(buttonType==leftButton){
        
        self.backBtn.hidden=isHidden;
        
    }else{
        
        self.rightBtn.hidden=isHidden;
    }
}

-(void)configButton{
    
    self.backBtn.imageView.contentMode=UIViewContentModeScaleAspectFit;
    self.rightBtn.imageView.contentMode=UIViewContentModeScaleAspectFit;
}

-(void)configTopView{
    
    
}

#pragma mark - add Action to button
-(void)addActionToBackBtn{
    
    [self.backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
}

-(void)addActionToRightBtn{
    
    [self.rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - action
-(void)backBtnAction{
    
    if([self.navBarDelegate respondsToSelector:@selector(leftButtonAction)]){
        
        [self.navBarDelegate leftButtonAction];
    }
}

-(void)rightBtnAction{
    
    if([self.navBarDelegate respondsToSelector:@selector(rightButtonAction)]){
        
        [self.navBarDelegate rightButtonAction];
    }
}

@end
